package com.icity.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.icity.entity.Menu;
import com.icity.entity.Role;
import com.icity.entity.RoleMenu;
import com.icity.entity.treemenu;
import com.icity.entity.twotreemenu;
import com.icity.entity.system.TableSupport;
import com.icity.mapper.SystemRoleMapper;
import com.icity.service.SystemRoleService;

@Service
public class SystemRoleServiceImpl implements SystemRoleService {

	@Autowired
	private SystemRoleMapper systemRoleMapper;

	

	@Override
	public TableSupport<Role> getRoleLsit(Map<Object, Object> map) {
		TableSupport<Role> listTable = new TableSupport<Role>();
		List<Role> listRole = systemRoleMapper.getroleList(map);
		int count = systemRoleMapper.getRoleCount(map);
		

		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listRole);
		return listTable;
	}
	
	@Override
	public boolean isExitroleByName(int id) {
		int count = systemRoleMapper.getroleCountByName(id);
		boolean flag = false;
		if(count>0){
			flag = true;
		}
		return flag;
	}
	
	@Override
	public int updateRole(Role role) {
		
		return systemRoleMapper.updateRole(role);
	}
	
	@Override
	public 	int saveRole(Role role) {
		
		return systemRoleMapper.saveRole(role);
	}
	
	@Override
	public 	int deleteRoleById(int id) {
		return systemRoleMapper.deleteRoleById(id);
		
	}

/*	
	@Override
	public List<Map<Object,Object>> select(){
		List<Map<Object,Object>> list =new ArrayList<Map<Object,Object>>();
		//查询一级菜单
		List<Menu> listmenu=systemRoleMapper.select();
		for (Menu menu : listmenu) {
			//根据一级菜单查询二级菜单
			
			List<Menu> twomenu=systemRoleMapper.selecttow(menu.getUnique_code());
			
		}
		return list;
	}
	*/
	@Override
	public List<Menu> onemen(){
		return systemRoleMapper.selectone();
				
	}
	
	@Override 
	public List<Menu> select(String parent_code){
		
		return systemRoleMapper.select(parent_code);
	}
	
	@Override
	public List<twotreemenu> selecttwo(String unique_code){
		return systemRoleMapper.selecttwo(unique_code);
		
	}
	
	@Override
	public int insetrrolemenu(RoleMenu roleMenu){
		return systemRoleMapper.insetrrolemenu(roleMenu);
		
	}
	
	@Override
	public 	List<Integer> getrolemenu(String roleId){
		return systemRoleMapper.getrolemenu(roleId);
		
	}
	
	
}
